//
// ***********************************************
// *    ___________   ___________  __      __    *
// *   |______  __/  /_____  ___/  \ \    / /    *
// *         / /          / /       \ \  / /     *
// *        / /          / /         \ \/ /      *
// *       / /          / /           \  /       *
// *      / /______    / /            / /        *
// *     /________/   /_/            /_/         *
// *                                             *
// ***********************************************
//
//  DTSDKWebView.h
//  DTSDK
//
//  Created by wanmeizty on 6/3/19.
//  Copyright © 2019年 wanmeizty. All rights reserved.
//

#import <WebKit/WebKit.h>

NS_ASSUME_NONNULL_BEGIN

@protocol DTApiDelegate <NSObject>

@required
/**
 * token失效 通过此方法可以重新授权
 *  失败后调用此方法重新授权
 * @param args 返回的失效信息
 **/
- (void)tokenFailed:(NSDictionary *)args;

@optional

/**
 * 说明 Web的返回按钮点击后调用该方法
 **/
-(void)goBack;

/**
 * 客户端实现跳转用户赚金币页面
 **/
-(void)earnGold;

/**
 * 用户金币兑换淘礼金成功后后的回调
 **/
-(void)consumeSuccess;

/**
 * 商品解析，获取正品保障等字段。参数为商品ID，异步调用
 **/
-(void)analyzeTbGoods:(NSString *)args;

@end

@interface DTSDKJsApi : NSObject

@property (weak,nonatomic) id<DTApiDelegate> delegate;

@end

typedef void (^JSCallback)(NSString * _Nullable result,BOOL complete);

@class DTSDKJsApi;
@interface DTSDKWebView : WKWebView

@property (nullable, nonatomic, weak) id <WKUIDelegate> DSUIDelegate;

/**
 * 加载Url
 * @param url 地址
 **/
- (void)loadUrl: (NSString *)url;

/**
 * refresh SDKWeb
 **/
-(void)refresh;

/**
 * 获取url
 * @param args 配置参数
 * @param isRelease 是否正式环境
 **/
-(NSString *)authorityUrl:(NSDictionary *)args environ:(BOOL)isRelease;

// Call javascript handler
-(void) callHandler:(NSString * _Nonnull) methodName  arguments:(NSArray * _Nullable) args;
-(void) callHandler:(NSString * _Nonnull) methodName  completionHandler:(void (^ _Nullable)(id _Nullable value))completionHandler;
-(void) callHandler:(NSString * _Nonnull) methodName  arguments:(NSArray * _Nullable) args completionHandler:(void (^ _Nullable)(id _Nullable value))completionHandler;

// set a listener for javascript closing the current page.
- (void)setJavascriptCloseWindowListener:(void(^_Nullable)(void))callback;

/**
 * Add a Javascript Object to dsBridge with namespace.
 * @param object
 * which implemented the javascript interfaces
 * @param namespace
 * if empty, the object have no namespace.
 **/
- (void)addJavascriptObject:(id _Nullable ) object namespace:(NSString *  _Nullable) namespace;

- (void)addJavascriptApi:(DTSDKJsApi *  _Nullable)jsapi;

- (void)addJavascriptApi:(DTSDKJsApi *  _Nullable)jsapi namespace:(NSString *  _Nullable) namespace;


//// Remove the Javascript Object with the supplied namespace
//- (void)removeJavascriptObject:(NSString *  _Nullable) namespace;

// Test whether the handler exist in javascript
- (void) hasJavascriptMethod:(NSString * _Nonnull) handlerName methodExistCallback:(void(^ _Nullable)(bool exist))callback;

// Set debug mode. if in debug mode, some errors will be prompted by a dialog
// and the exception caused by the native handlers will not be captured.
- (void) setDebugMode:(bool) debug;

- (void) disableJavascriptDialogBlock:(bool) disable;

// custom the  label text of  javascript dialog that includes alert/confirm/prompt
- (void) customJavascriptDialogLabelTitles:(NSDictionary*_Nullable) dic;

// private method, the developer shoudn't call this method
- (id _Nullable ) onMessage:(NSDictionary *_Nonnull) msg type:(int) type;

@end

NS_ASSUME_NONNULL_END
